﻿/**
 * Licensed under the MIT License
 *
 * Copyright (c) 2010 Alexandre Croiseaux
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */
package marcel.display.gui.buttons
{
	import flash.text.*;
	import marcel.display.View;
	
	/**
	 * A simple button with text
	 * @author Alexandre Croiseaux
	 */
	public class SimpleTextButton extends ColorButton
	{
		//--------------------------------------------------------------------------
		//
		//  Private vars
		//
		//--------------------------------------------------------------------------
		private var _textField:TextField;
		
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		/**
		 * Constructs a new TextButton instance
		 * @param	text		text of the button, centered
		 * @param	textColor	color of the text
		 * @param	bgColor		color of the button background
		 * @param	bgOverColor	color of the button background when mouse is over the button
		 */
		public function SimpleTextButton(text:String, textColor:int = 0xFFFFFF, bgColor:int = 0, bgOverColor:int = 0x999999)
		{
			_textField = new TextField();
			_textField.defaultTextFormat = new TextFormat("Verdana", 10, textColor, true);
			_textField.text = text;
			_textField.selectable = false;
			_textField.x = 2;
			_textField.y = 2;
			_textField.autoSize = TextFieldAutoSize.LEFT;
			
			addChild(_textField);
			var v:View = createDefaultBound();
			registerColor(v, bgOverColor, bgColor);
			
			sensor.alpha = 1;
			setOut();
		}
		
		
		//--------------------------------------------------------------------------
		//
		//  Public methods
		//
		//--------------------------------------------------------------------------
		/**
		 * Sets the new label text of the button
		 * @param	text	A string used as button label
		 */
		public function setText(text:String):void
		{
			_textField.text = text;
		}
		
		
		//--------------------------------------------------------------------------
		//
		//  Private methods
		//
		//--------------------------------------------------------------------------
		
		
		//--------------------------------------------------------------------------
		//
		//  Events
		//
		//--------------------------------------------------------------------------
	}
}
